import { assert, beforeAll, describe, test } from 'vitest';
import { CHECK_MODE, testCaseCheck } from '../common/testCommon';
import AdjacentOverloadCheckDSL from '../../../../src/checker/dsl/AdjacentOverloadSignatureDsl';
import path from 'path';
import { CheckEntry, Rule } from '../../../../src/Index';

let realPath: string = '';
let checkEntry: CheckEntry;

beforeAll(async () => {
    const rule: Rule = new Rule('');
    checkEntry = await testCaseCheck(
        './test/unittest/sample/AdjacentOverloadSignatruesDsl',
        rule,
        CHECK_MODE.FILE2CHECK,
        AdjacentOverloadCheckDSL,
        false,
        true
    );
    realPath = checkEntry.scene.getRealProjectDir();
});

describe('AdjacentOverloadCheckDSLTest', () => {
    test('AdjacentOverloadCheckDSLTest_001', () => {
        const detectFile: string = path.join(realPath, 'AdjacentOverloadSignatureDslReport.ts');
        const expectReportList = ['1%1', '7%1']; 
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.isDefined(detectFileReport, 'The file path is error.');
        assert.equal(detectFileReport?.issues.length, expectReportList.length, 'The number of reported line is different from expected.');
        detectFileReport?.issues.forEach((issue, index) => {
            assert.include(issue.defect.fixKey, expectReportList[index]);
        });
    });

    test('AdjacentOverloadCheckDSLTest_002', () => {
        const detectFile: string = path.join(realPath, 'AdjacentOverloadSignatureDslNoReport.ts');
        const detectFileReport = checkEntry.fileChecks.find(fileCheck => fileCheck.arkFile.getFilePath() === detectFile);
        assert.equal(detectFileReport?.issues.length, 0, 'No issue should be reported.');
    });
});
